data = transpose (dataT)
function lr (pw){
return (
Plot. plot ({
marks : [
Plot. dot (data, {x : "x" , y : "y" }),
Plot. line (curve (data), {x : "x" , y : "y" }),
Plot. ruleX ([0 ], {stroke : "gray" }), // Add a vertical line at x=0
Plot. ruleY ([80 ], {stroke : "gray" })
],
y : {
label : "Blutdruck" ,
domain : [80 , 200 ],
labelFontSize : 50
},
x : {
label : "Alter" ,
domain : [0 , 80 ]
},
width : pw,
height : pw/ 1.5 ,
color : "steelblue"
})
)
}
function curve (template){
const ages = template. map (d => d. x );
const [minAge, maxAge] = d3. extent (ages);
const xvals = d3. range (minAge, maxAge, (maxAge - minAge) / 100 );
let yhat = xvals. map (x => w* x + b);
return xvals. map ((x, i) => ({x, y : yhat[i]})); //Thanks ChatGPT
}
lr (900 )